<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>切换</title>
    <style>
        .box
        {
            width: 100px;
            height: 100px;
            color: #fff;
            background-color: red;
            /* display: inline-block; */
            margin-right: 40px;
            text-align: center;
        }
    </style>
</head>
<body>

    <div  class="box">
       我是div盒子
    </div>
    <button>切换</button>
    
    <script>
        var btnEl = document.querySelector("button");
        var boxEl = document.querySelector(".box");
        
        btnEl.onclick = function ()
        {
           boxEl.hidden = !boxEl.hidden;
        }
    </script>
    
</body>
</html>